﻿using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using VOL.Core.Extensions;
using VOL.Core.Utilities;
using VOL.Entity.DomainModels;
using VOL.Entity.DomainModels.BasicData;
using VOL.SmartMecial.Infrastructure;
using VOL.SmartMecial.IServices.BasicData;

namespace VOL.SmartMecial.Services.BasicData
{
    public class PrinitService : IPrinitService
    {
        private readonly IBaseRepository<Patient> _patientRepository;
        private readonly IBaseRepository<Entity.DomainModels.WardArea> _wardAreaRepository;

        public PrinitService(IBaseRepository<Patient> patientRepository, IBaseRepository<Entity.DomainModels.WardArea> wardAreaRepository)
        {
            this._patientRepository = patientRepository;
            this._wardAreaRepository = wardAreaRepository;
        }

        public async Task<WebResponseContent> GetPatientList(string? wardAreaCode, string? bedCode)
        {
            var list = _patientRepository.GetAll();
            list = list.WhereIF(!string.IsNullOrEmpty(wardAreaCode), o => o.WardAreaCode == wardAreaCode);
            list = list.WhereIF(!string.IsNullOrEmpty(bedCode), o => o.BedCode == bedCode);
            var data = await list.ToListAsync();
            var response = new WebResponseContent();
            response.OK("查询成功", data);
            return await Task.FromResult(response);
        }

        public async Task<WebResponseContent> GetWardAreas()
        {
            var res = new WebResponseContent();
            var list = await _wardAreaRepository.GetAll().ToListAsync();
            res.OK("查询病区列表成功", list);
            return await Task.FromResult(res);
        }
    }
}
